home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 650 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.4 KB

  1. Path: engnews1.Eng.Sun.COM!taumet!clamage
  2. From: willer@carolian.com (Steve Willer)
  3. Newsgroups: comp.std.c++
  4. Subject: auto_ptr: no operator bool()?
  5. Date: 6 Mar 1996 19:30:16 GMT
  6. Organization: Carolian Systems, Toronto ON
  7. Sender: news@sq.com (News Administrator)
  8. Approved: clamage@eng.sun.com (comp.std.c++)
  9. Message-ID: <313ddfd9.16044605@sqarc.sq.com>
  10. NNTP-Posting-Host: taumet.eng.sun.com
  11. Content-Type: text
  12. Content-Length: 1887
  13. X-Lines: 41
  14. X-Newsreader: Forte Agent .99d/32.182
  15. Originator: clamage@taumet
  16.  
  17. I hope I don't sound like I'm second-guessing people who are likely much more
  18. experienced than I am in library design, but I have another question about
  19. auto_ptrs.
  20.  
  21. Specifically, the (April '95) draft standard auto_ptr doesn't have an operator
  22. bool() function in it, making it inconvenient to write "if (ptr)" type
  23. constructs. Is there some sort of reason for that? I know that implicit type
  24. conversion is generally a bad thing, but I can't see how this one would be
  25. particularly dangerous (also, can the new explicit keyword be used on the
  26. return type?).
  27.  
  28. Now, Meyers's latest book describes an auto_ptr that has member templates, so
  29. obviously the April WP does not have the latest auto_ptr, but I get the
  30. impression even the current auto_ptr doesn't have an operator bool(). My
  31. reading of Meyers's discussion of smart_ptrs mentions that operator bool()
  32. would allow comparison of two different types of auto_ptrs, but the latest
  33. iostream standard has an operator bool() and an operator!() defined. So why not
  34. be consistent?
  35.  
  36. In fact, as another idea, what about defining a new class, say, explicit_bool?
  37. explicit_bool would have an operator bool() defined, but would also have an
  38. operator==(const explicit_bool &rhs) and operator!=(const explicit_bool &rhs)
  39. defined as a private function. It would also have operator!() return an
  40. explicit_bool. This way, constructs such as "if (myptr)" and "if (!myptr)"
  41. would work, but "if (myptr==otherptr)" and "if (myptr != otherptr)" wouldn't
  42. compile.
  43.  
  44. Just a thought, anyway. I'm sure there are holes in that idea.
  45.  
  46.  
  47.  
  48. [ comp.std.c++ is moderated.  To submit articles: Try just posting with your
  49.                 newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  50.   comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  51.   Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  52.   Comments? mailto:std-c++-request@ncar.ucar.edu
  53. ]
  54.